<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Vendors extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('v_vendors');
	}
	
	public function getvendors()
	{
		$this->load->model('m_vendors');
		
		$json = $this->m_vendors->get_vendors();
		
		$jsonObject = json_decode($json);
		
		$aaData = array();
		
		foreach($jsonObject->aaData as $row)
		{
			$row['5'] = '<a href="' . $row['5'] . '">' . $row['5'] . '</a>';
			
			$recordset = $this->m_vendors->get_user_id($this->session->userdata('useremail'));
			$results = $recordset->result();
			$userid = $results[0]->userId;
			
			$recordset = $this->m_vendors->linkexists($userid, $row['6']);
			$results = $recordset->result();
			
			if(count($results) == 0)
			{
				$row['6'] = '<a class="btn" href="' . site_url("linktovendor/index/" . $row['6']) . '">Link</a>';
			}
			else
			{
				$row['6'] = '<s>Link</s>';
			}
			array_push($aaData, $row); 
		}
		
		$jsonObject->aaData = $aaData;
		
		echo json_encode($jsonObject);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */